<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="BootStrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="layui-v2.5.7/layui/css/layui.css"/>
    <script src="layui-v2.5.7/layui/layui.js"></script>
    <script src="javascript/jquery.js"></script>
    <script src="BootStrap/js/bootstrap.min.js"></script>
</head>
<!--
    @Author: LuXi
    销售报表
 -->
<body>
<section class="page-hd">
    <header>
        <h3 class="title"><font color="#d3d3d3">报表</font>/<font>销售报表</font></h3>
    </header>
    <hr>
</section>

<!-- 搜索模块 -->
<form class="layui-form layui-form-pane" id="search_form">
    <!--当前页-->
    <input type="hidden" name="pageNum" />
    <div class="layui-form-item">
        <label class="layui-form-label">股东/分销商</label>
        <div class="layui-input-inline">
            <select name="user" id="shareholder" lay-search>
                <option value="0" selected>--股东/分销商--</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">选择医院</label>
            <div class="layui-input-inline">
                <select name="hospital" id="select_hospital" lay-search>
                    <option value="0" selected>--所有医院--</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">选择科室</label>
            <div class="layui-input-inline">
                <select name="department" id="select_department" lay-search>
                    <option value="0" selected>--所有科室--</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <button type="button" onclick="search_all()" class="layui-btn layui-btn-normal ">搜索</button>
                <button type="button" onclick="form_reset()" class="layui-btn layui-btn-primary ">清除</button>
            </div>
        </div>
    </div>
</form>

<hr/>

<!-- 表格数据模块 -->
<table class="layui-table" style="text-align: center;" lay-skin="line">
    <thead>
    <tr>
        <th style="text-align: center">日期</th>
        <th style="text-align: center">股东/分销商</th>
        <th style="text-align: center">医院名称</th>
        <th style="text-align: center">科室名称</th>
        <th style="text-align: center">床位数（张）</th>
        <th style="text-align: center">租赁次数（次）</th>
        <th style="text-align: center">总租金（元）</th>
    </tr>
    </thead>
    <tbody id="tbody">

    </tbody>
</table>

<!--页码-->
<div class="container">
    <div class="row" style="margin-right: 40%;">
        <ul class="pagination pull-right" id="pages">
        </ul>
    </div>
</div>

<script>
    layui.use('form', function () {
        var form = layui.form;
        show(form);
    });

    //展示
    function show(form) {
        $.ajax({
            url:"/baobiao/xiaoshou",
            type:"post",
            data:$("#search_form").serialize(),
            success:function (data) {
                if(data.result){
                    //股东select
                    var share = "";
                    $.each(data.map.users,function (index,user) {
                        share += "<option value='"+user.userid+"' >"+user.username+"</option>"
                    });
                    $("#shareholder").append(share);

                    var hospital="";
                    $.each(data.map.hospital,function (index,h) {
                        hospital+="<option value='"+h.hospitalinfoid+"' >"+h.hospitalinfoname+"</option>";
                    });
                    $("#select_hospital").append(hospital);

                    var department="";
                    $.each(data.map.department,function (index,d) {
                        department+="<option value='"+d.departmentid+"' >"+d.departmentname+"</option>";
                    });
                    $("#select_department").append(department);
                    //去重
                    $("select option").each(function() {
                        text = $(this).text();
                        if($("select option:contains("+text+")").length > 1)
                            $("select option:contains("+text+"):gt(0)").remove();
                    });

                    //表格
                    var list = "";
                    $.each(data.map.orders,function (index,order) {
                        list += "<tr>";
                            list += "<td>"+order.userorderstarttime.substring(0,order.userorderstarttime.indexOf(" "))+"</td>";
                            list += "<td>"+order.username+"</td>";
                            list += "<td>"+order.hospital+"</td>";
                            list += "<td>"+order.department+"</td>";
                            list += "<td>"+order.cwCount+"</td>";
                            list += "<td>"+order.zlCount+"</td>";
                            list += "<td>"+order.money+"</td>";
                        list += "</tr>";
                    });
                    $("#tbody").html(list);
                    pageLoad(data.map.pageInfo);
                    pageClick(data.map.pageInfo.pages);
                    //重新渲染select
                    form.render('select');
                }else{
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg('Error...', {icon: 5});
                    });
                }
            }
        });
    }
    //分页
    function pageLoad(data) {
        var str = "<li><a href='"+(data.pageNum - 1)+"'>上一页</a></li>";
        str += "<li class='active'><a>"+data.pageNum+"</a></li>";
        str += "<li><a href='"+(data.pageNum + 1)+"'>下一页</a></li>";
        str += "<li><a>共"+data.pages+"页</a></li>";
        $("#pages").html(str);
    }
    function pageClick(pages) {
        $("#pages a").click(function () {
            var cutPage = $(this).attr("href");
            if(cutPage > pages){
                cutPage = pages;
            }
            if(cutPage < 1){
                cutPage = 1;
            }
            $(":hidden[name=pageNum]").val(cutPage);
            show();
            return false;
        });
    }













    //搜索
    function search_all() {
        show();
    }


    //清除表单
    function form_reset() {
        $("#search_form")[0].reset();
        show();
    }
</script>
</body>
</html>